package cn.jasonone.resolvers;

import cn.jasonone.views.ExcelView;
import cn.jasonone.views.QRCodeView;
import lombok.Data;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.view.UrlBasedViewResolver;

import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Locale;

/**
 * excel视图解析器
 * @author xujie
 * @version 1.0.0
 */
@Data
public class QRCodeResolver extends UrlBasedViewResolver {
    private String prefix;
    private String suffix;

//    @Override
//    protected Class<?> getViewClass() {
//        return ExcelView.class;
//    }


    public QRCodeResolver() {
        this.setViewClass(QRCodeView.class);
    }

    @Override
    public View resolveViewName(String viewName, Locale locale) throws Exception {
        String path = getServletContext().getRealPath(this.prefix + viewName + this.suffix);
        if(Files.exists(Paths.get(path))){
            return new QRCodeView(path);
        }else{
            return null;
        }
    }
}
